"use strict";
/* Controllers */
app.controller("dashboardController", ['$scope', '$location', '$rootScope', '$routeParams', 'dashboardService', function ($scope, $location, $rootScope, $routeParams, dashboardService) {

    var vm = $scope.vm = {};
    vm.p = {};
    vm.result = {};
    vm.p.transOrderID = $routeParams.ID; //  获取应用模块的名称
    vm.p.license = 0;
    vm.p.subBillID = 0;
    vm.p.productCode = 0;
    //vm.p.license = "";
    //vm.p.subBillID ="";
    //vm.p.productCode = "";
    //vm.p.pageInfo = {pageSize:30, pageNum:1};

    var errorFn = function (result) {
        alert(result);
    };

    $scope.queryYarnQueue = function () {
        var vm = $scope.vm;
        vm.result.ms = "...";
        var param = {};
        var procFn = function (response) {
            var data = [
                {clusterName:'off', queue:'root.ai', appCount:1},
                {clusterName:'off', queue:'root.ai', appCount:11},
                {clusterName:'off', queue:'root.ai', appCount:111}
            ];
            $('#list_table_queue').bootstrapTable('load', data);
        };
        dashboardService.queryYarnQueue(param, procFn, errorFn);
    };

    $scope.queryHdfsTable = function () {
        var vm = $scope.vm;
        vm.result.ms = "...";
        var param = {};
        var procFn = function (response) {
            var data = [
                {clusterName:'off', dbName:'db.ai', tableCount:1},
                {clusterName:'off', dbName:'db.ai', tableCount:11},
                {clusterName:'off', dbName:'db.ai', tableCount:111}
            ];
            $('#list_table').bootstrapTable('load', data);
        };
        dashboardService.queryHdfsTable(param, procFn, errorFn);
    };

    $scope.initializeController = function () {
        vm.result.ms = '';

        var $resultTableQueue = $('#list_table_queue');
        $resultTableQueue.bootstrapTable({
             pageList: [30, 50, 100, 300, 500, 1000], pageSize: 30
        });
        $scope.queryYarnQueue();


        var $resultTable = $('#list_table');
        $resultTable.bootstrapTable({
             pageList: [30, 50, 100, 300, 500, 1000], pageSize: 30
        });
        $scope.queryHdfsTable();
    };

    $scope.initializeController();

}]);


/* Services */
app.service('dashboardService', ['ajaxService', function (ajaxService) {

    this.queryYarnQueue = function (params, successFunction, errorFunction) {
        ajaxService.AjaxPost(params, "/star/api/basic-service/v1/dashboard/queryYarnQueue.do", successFunction, errorFunction);
    };

    this.queryHdfsTable = function (params, successFunction, errorFunction) {
        ajaxService.AjaxPost(params, "/star/api/basic-service/v1/dashboard/queryHdfsTable.do", successFunction, errorFunction);
    };
}]);


function queueDashboardOptFmt(value, row, index) {
    if (value == null) {
        return "-";
    }
    return [
        '<a href="#/star/order/yarn_application_list/', row.clusterName, '/', value, '" target="_blank">', "<u>查看任务</u>" , '</a>'
    ].join('');
}
function dbOptFmt(value, row, index) {
    if (value == null) {
        return "-";
    }
    return [
        '<a href="#/star/order/hdfs_table_list/', row.clusterName, '/', value, '" target="_blank">', "<u>查看库表</u>" , '</a>'
    ].join('');
}
